function selApp() {
    $.ajaxSettings.async = false;
    $.getJSON("/wxw/selapp", function (data) {
        $(data).each(function (i, j) {
            $abc = "<option value='" + (i + 1) + "'>" + j.valueName + "</option>";
            $("#selapp").append($abc)
        })
    })
    $.ajaxSettings.async = true;
}


function selPing() {
    $.ajaxSettings.async = false;

    $.getJSON("/wxw/selping", function (data) {
        $(data).each(function (i, j) {
            $abc = "<option value='" + (i + 1) + "'>" + j.valueName + "</option>";
            $("#selping").append($abc)
        })
    });
    $.ajaxSettings.async = true;
}

function selYi() {

    $.ajaxSettings.async = false;

    $.getJSON("/wxw/selYi", function (data) {
        $(data).each(function (i, j) {
            $abc = "<option value='" + j.id + "'>" + j.categoryName + "</option>";
            $(".tl123").append($abc)
        })
    });
    $.ajaxSettings.async = true;
}

function selEr() {
    $("#queryCategoryLevel2").children().remove()
    $("#queryCategoryLevel3").children().remove()
    let id = $("#queryCategoryLevel1").val();
    let json = {
        id: id
    }
    $.ajaxSettings.async = false;
    $.getJSON("/wxw/selEr", json, function (data) {
        $(data).each(function (i, j) {

            $abc = "<option value='" + j.id + "'>" + j.categoryName + "</option>";
            $("#queryCategoryLevel2").append($abc)
        })
    });
    $.ajaxSettings.async = true;
    selSan()
}

function selSan() {
    $("#queryCategoryLevel3").children().remove()
    let id = $("#queryCategoryLevel2").val();
    let json = {
        id: id
    }
    $.ajaxSettings.async = false;
    $.getJSON("/wxw/selSan", json, function (data) {
        $(data).each(function (i, j) {

            $abc = "<option value='" + j.id + "'>" + j.categoryName + "</option>";
            $("#queryCategoryLevel3").append($abc)
        })
    });
    $.ajaxSettings.async = true;
}

var currentPage = 1;
var pageSize = 5;
var totalPage = 1;//总页数
var totalCount = 1;//总条数
function selList() {
    $(".wxw1").find("tr:gt(0) td").html("&nbsp;")
    let querySoftwareName = $("#querySoftwareName").val();
    let queryStatus = $("#selapp").val();
    let queryFlatformId = $("#selping").val();
    let queryCategoryLevel1 = $("#queryCategoryLevel1").val();
    let queryCategoryLevel2 = $("#queryCategoryLevel2").val();
    let queryCategoryLevel3 = $("#queryCategoryLevel3").val();
    let json = {
        querySoftwareName: querySoftwareName,
        queryStatus: queryStatus,
        queryFlatformId: queryFlatformId,
        queryCategoryLevel1: queryCategoryLevel1,
        queryCategoryLevel2: queryCategoryLevel2,
        queryCategoryLevel3: queryCategoryLevel3,
        currentPage: currentPage,
        pageSize: pageSize
    }
    $.ajaxSettings.async = false;
    $.getJSON("/wxw/selList", json, function (data) {
        totalPage = data.pages;
        totalCount = data.total;
        $(data.list).each(function (i, j) {
            $("#datatable-responsive").find("tr").eq(i + 1).find("td").eq(0).text(j.softwareName)
            $("#datatable-responsive").find("tr").eq(i + 1).find("td").eq(1).text(j.apkname)
            $("#datatable-responsive").find("tr").eq(i + 1).find("td").eq(2).text(j.softwareSize)
            $("#datatable-responsive").find("tr").eq(i + 1).find("td").eq(3).text(j.valueName)
            $("#datatable-responsive").find("tr").eq(i + 1).find("td").eq(4).text(j.categoryLevel1 + "->" + j.categoryLevel2 + "->" + j.categoryLevel3)
            $("#datatable-responsive").find("tr").eq(i + 1).find("td").eq(5).text(j.status)
            $("#datatable-responsive").find("tr").eq(i + 1).find("td").eq(6).text(j.downloads)
            $("#datatable-responsive").find("tr").eq(i + 1).find("td").eq(7).text(j.versionNo)
            $("#datatable-responsive").find("tr").eq(i + 1).find("td").eq(8).html("<select onchange='caozuo(this," + j.id + ")'><option>点击操作</option>" +
                "<option value='1'>新增版本</option>" +
                "<option value='2'>修改版本</option>" +
                "<option value='3'>修改</option>" +
                "<option value='4'>查看</option>" +
                "<option value='5'>删除</option>" +
                "<option value='6'>上架</option>" +
                "<option value='7'>下架</option>" +
                "</select>")
        })

    })
    $.ajaxSettings.async = true;
    showData();
}

function showData() {
    $("#datatable-responsive_info").text("共" + totalCount + "条记录 第" + currentPage + "页/共" + totalPage + "页");
    if (currentPage > 1) {
        $(".pagination").html("<li class=\"paginate_button previous\"><a href=\"javascript:;\" onclick=\"first()\" aria-controls=\"datatable-responsive\" data-dt-idx=\"0\" tabindex=\"0\">首页</a></li>\n" +
            "\t\t\t\t\t\t\t\t\t<li class=\"paginate_button \"><a href=\"javascript:;\" onclick=\"prev()\" aria-controls=\"datatable-responsive\" data-dt-idx=\"1\" tabindex=\"0\">上一页</a></li>");
    }
    if (currentPage < totalPage) {
        $(".pagination").html("<li class=\"paginate_button \"><a href=\"javascript:;\" aria-controls=\"datatable-responsive\" onclick=\"next()\" data-dt-idx=\"1\" tabindex=\"0\">下一页</a></li>\n" +
            "\t\t\t\t\t\t\t\t\t<li class=\"paginate_button next\"><a href=\"javascript:;\" aria-controls=\"datatable-responsive\" onclick=\"end()\" data-dt-idx=\"7\" tabindex=\"0\">尾页</a></li>");
    }
}


function caozuo(thisA, id) {
    var name = $(thisA).parents("td").prev().prev().prev().text().trim();
    let num = $(thisA).val();
    let cid = id;
    let json = {
        id: cid
    }
    if (num == 1) {//新增版本
        location.href = "/version/add/"+cid;
    } else if (num == 2) {//修改版本
        location.href = "/version/toupd/"+cid;
    } else if (num == 3) {//修改
        if (name=="待审核"||name=="审核未通过"){
            location.href = "/wxw/updaInfo/" + cid+"/"+name;
        }else{
            confirm("改App的状态为["+name+"],不给予修改");
            selList()
            return;
        }

    } else if (num == 4) {//查看
        location.href = "/version/infoview/"+cid;
    } else if (num == 5) {//删除
        let bo = confirm("你是否确认删除？");
        if (bo == false) {
            selList()
            return
        }
        $.getJSON("/wxw/delInfo", json, function (data) {
            if (data == "true") {
                selList();
            } else {
                selList();
            }
        })
    } else if (num == 6) {//上架
        let bo = confirm("你是否确认上架？");
        if (bo == false) {
            selList()
            return
        }
        $.getJSON("/wxw/updaInfoShang", json, function (data) {
            if (data == "true") {
                selList();
            } else {
                selList();
            }
        })
    } else if (num == 7) {//下架

        let bo = confirm("你是否确认下架？");
        if (bo == false) {
            selList()
            return
        }
        $.getJSON("/wxw/updaInfoXia", json, function (data) {
            if (data == "true") {
                selList();

            } else {
                selList();
            }
        })
    }
}

function first() {
    currentPage = 1;
    selList();
}

function next() {
    currentPage++;
    if (currentPage > totalPage) {
        return;
    }
    selList();
}

function prev() {
    currentPage--;
    if (currentPage < 1) {
        return;
    }
    selList();
}

function end() {
    currentPage = totalPage;
    selList();
}